﻿using System;
using System.Data;
using System.Collections.Generic;
using Maticsoft.Common;
using Adrr.Model;
namespace Adrr.BLL
{
	/// <summary>
	/// VersionNo
	/// </summary>
	public partial class VersionNo
	{
		private readonly Adrr.DAL.VersionNo dal=new Adrr.DAL.VersionNo();
		public VersionNo()
		{}
		#region  Method

		/// <summary>
		/// 得到最大ID
		/// </summary>
		public int GetMaxId()
		{
			return dal.GetMaxId();
		}

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int VersionID)
		{
			return dal.Exists(VersionID);
		}

		/// <summary>
		/// 增加一条数据
		/// </summary>
		public int  Add(Adrr.Model.VersionNo model)
		{
			return dal.Add(model);
		}

		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(Adrr.Model.VersionNo model)
		{
			return dal.Update(model);
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int VersionID)
		{
			
			return dal.Delete(VersionID);
		}
		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool DeleteList(string VersionIDlist )
		{
			return dal.DeleteList(VersionIDlist );
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public Adrr.Model.VersionNo GetModel(int VersionID)
		{
			
			return dal.GetModel(VersionID);
		}

		/// <summary>
		/// 得到一个对象实体，从缓存中
		/// </summary>
		public Adrr.Model.VersionNo GetModelByCache(int VersionID)
		{
			
			string CacheKey = "VersionNoModel-" + VersionID;
			object objModel = Maticsoft.Common.DataCache.GetCache(CacheKey);
			if (objModel == null)
			{
				try
				{
					objModel = dal.GetModel(VersionID);
					if (objModel != null)
					{
						int ModelCache = Maticsoft.Common.ConfigHelper.GetConfigInt("ModelCache");
						Maticsoft.Common.DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
					}
				}
				catch{}
			}
			return (Adrr.Model.VersionNo)objModel;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			return dal.GetList(strWhere);
		}
		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			return dal.GetList(Top,strWhere,filedOrder);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<Adrr.Model.VersionNo> GetModelList(string strWhere)
		{
			DataSet ds = dal.GetList(strWhere);
			return DataTableToList(ds.Tables[0]);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<Adrr.Model.VersionNo> DataTableToList(DataTable dt)
		{
			List<Adrr.Model.VersionNo> modelList = new List<Adrr.Model.VersionNo>();
			int rowsCount = dt.Rows.Count;
			if (rowsCount > 0)
			{
				Adrr.Model.VersionNo model;
				for (int n = 0; n < rowsCount; n++)
				{
					model = new Adrr.Model.VersionNo();
					if(dt.Rows[n]["VersionID"]!=null && dt.Rows[n]["VersionID"].ToString()!="")
					{
						model.VersionID=int.Parse(dt.Rows[n]["VersionID"].ToString());
					}
					if(dt.Rows[n]["PhoneType"]!=null && dt.Rows[n]["PhoneType"].ToString()!="")
					{
					model.PhoneType=dt.Rows[n]["PhoneType"].ToString();
					}
					if(dt.Rows[n]["PublishTime"]!=null && dt.Rows[n]["PublishTime"].ToString()!="")
					{
						model.PublishTime=DateTime.Parse(dt.Rows[n]["PublishTime"].ToString());
					}
					if(dt.Rows[n]["VerName"]!=null && dt.Rows[n]["VerName"].ToString()!="")
					{
					model.VerName=dt.Rows[n]["VerName"].ToString();
					}
					if(dt.Rows[n]["VerDesp"]!=null && dt.Rows[n]["VerDesp"].ToString()!="")
					{
					model.VerDesp=dt.Rows[n]["VerDesp"].ToString();
					}
					if(dt.Rows[n]["IsMustUp"]!=null && dt.Rows[n]["IsMustUp"].ToString()!="")
					{
						if((dt.Rows[n]["IsMustUp"].ToString()=="1")||(dt.Rows[n]["IsMustUp"].ToString().ToLower()=="true"))
						{
						model.IsMustUp=true;
						}
						else
						{
							model.IsMustUp=false;
						}
					}
					if(dt.Rows[n]["CreateTime"]!=null && dt.Rows[n]["CreateTime"].ToString()!="")
					{
						model.CreateTime=DateTime.Parse(dt.Rows[n]["CreateTime"].ToString());
					}
					if(dt.Rows[n]["LastVersion"]!=null && dt.Rows[n]["LastVersion"].ToString()!="")
					{
						model.LastVersion=int.Parse(dt.Rows[n]["LastVersion"].ToString());
					}
					if(dt.Rows[n]["Operation"]!=null && dt.Rows[n]["Operation"].ToString()!="")
					{
					model.Operation=dt.Rows[n]["Operation"].ToString();
					}
					if(dt.Rows[n]["Status"]!=null && dt.Rows[n]["Status"].ToString()!="")
					{
						model.Status=int.Parse(dt.Rows[n]["Status"].ToString());
					}
					if(dt.Rows[n]["DownloadUrl"]!=null && dt.Rows[n]["DownloadUrl"].ToString()!="")
					{
					model.DownloadUrl=dt.Rows[n]["DownloadUrl"].ToString();
					}
					modelList.Add(model);
				}
			}
			return modelList;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetAllList()
		{
			return GetList("");
		}

		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			return dal.GetRecordCount(strWhere);
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			return dal.GetListByPage( strWhere,  orderby,  startIndex,  endIndex);
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		//public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		//{
			//return dal.GetList(PageSize,PageIndex,strWhere);
		//}

		#endregion  Method
	}
}

